class Subcategory < ActiveRecord::Base
  validates_presence_of :subcategory_name
  validates_length_of :subcategory_name, :within => 2..255

  belongs_to :category
  has_many :items

  attr_accessor :new_category_name
  before_save :create_category_from_name

  def create_category_from_name
    unless new_category_name.blank?
      self.category = Category.find_or_create_by_category_name(new_category_name)
    end
  end
end
